using System.Collections.Generic;
using System.Collections;
using System;

namespace ObjectTransposeApi.Handler.Expand
{
	/// <summary/>
	internal class HashTableExpandHandler : AbstractExpandHandler
	{
        /// <summary/>
        internal override IEnumerable<object> Process(object value)
        {
            // if the value a hash table then handle it ... (remember the type has the enumerable interface)
            if (!typeof(Hashtable).IsInstanceOfType(value))
            {
                return base._successor.Process(value);
            }

            // add one at a time because the generics and non-generics enumerable don't match up ... use
            // an enumerator because the variable 'value' is already used and I can't think what to call it
            IDictionaryEnumerator dictionaryEnumerator = ((Hashtable)value).GetEnumerator();

            List<object> parsedValues = new List<object>();

            while(dictionaryEnumerator.MoveNext())
            {
                parsedValues.Add(dictionaryEnumerator.Value);
            }

            return parsedValues;
        }
    }
}

